<template>
    <div class="container">
        <el-radio-group v-model="ruleForm.parentId">
            <el-radio v-for="(item,index) in list" :key="index" :label="item.id">
                {{item.name}}
            </el-radio>
        </el-radio-group>
        <el-form ref="form" :model="ruleForm" label-width="130px">
            <el-row :gutter="20" style="margin-top:20px;">
                <el-col :span="12">
                    <el-radio v-model="ruleForm.type" label="MENU">模块</el-radio>
                    <el-radio v-model="ruleForm.type" label="FUNC">功能</el-radio>
                    <el-form-item label="模块名称" >
                        <el-input class="handle-input" style="width:300px;"  v-model="ruleForm.name"></el-input>
                    </el-form-item>
                    <el-form-item label="排序" >
                        <el-input class="handle-input" style="width:300px;"  v-model="ruleForm.sortNum"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <el-button @click="addpermission">新增</el-button>
    </div>
</template>

<script>
import {control_resourcesave,control_get} from "@/request/api"
    export default {
        data(){
            return{
                list:'',
                ruleForm:{
                    type:'',
                    appId:'',
                    name:'',
                    sortNum:'',
                    parentId:'',
                    customAppId:''
                }
            }
        },
        mounted(){
            
            this.ruleForm.appId = this.$route.query.appId
            this.get()
        },
        methods:{
            get(){
                control_get(this.ruleForm.appId).then((res)=>{
                    this.list = res.data
                })
            },
            addpermission(){
                if(this.ruleForm.type == "MENU"){
                    this.ruleForm.parentId = ""
                }
                if(this.ruleForm.type == "FUNC"){
                    
                }
                let data = this.ruleForm
                // console.log(data)
                control_resourcesave(data).then((res)=>{
                    this.get()
                    alert(1)
                })
            }
        }
    }
</script>

<style scoped>

</style>